
drop if ( famrel==0) & age < 15
keep if asecwt>0
tab age

g age_1 = age
g age_2 = age^2
g age_3= age^3
g age_4 = age^4

gen dem_hisp = .
replace dem_hisp = 0 if inlist(hisp,0,901,902)
replace dem_hisp = 1 if inrange(hisp,100,700)
gen dem_race = race

gen dem_educ = .
* replace dem_educ = 0 if inrange(educ,1,1) //NIU
replace dem_educ = 1 if inrange(educ,1,72) //LTHS
replace dem_educ = 2 if inrange(educ,73,73) //HSD
replace dem_educ = 3 if inrange(educ,80,100) //some col
replace dem_educ = 4 if inrange(educ,110,111) //col degree
replace dem_educ = 5 if inrange(educ,120,125) //anvanced

gen byte post2002 = year >= 2003
gen byte pre1988 = year <= 1988


gen dem_married = marst


gen dem_female = sex == 2

egen fam_prime_id = group(state_fips  year serial asecfw)
egen num_fam_prime = count(fam_prime_id) ,by(state_fips serial  year asecfw )
recode inctot 999999999=.
egen inc_fam_prime = total(inctot) ,by(fam_prime_id)

gen dem_famsize= num_fam_prime

gen byte u18 = age < 18
egen nchildu18 = total(u18),by(state_fips year serial fam_prime_id)
replace nchildu18 = 0 if nchild ==0
gen dem_nchild = nchildu18

recode offtotval 9999999999=.
drop if offcutoff==.

gen povcut = offcutoff
gen contpov = offtotval / povcut
recode contpov (min/0 = 0) (100/max = 100)

gen contpov_dube = inc_fam_prime / povcut
recode contpov_dube (min/0 = 0) (100/max = 100)

* credits = child credit + additional child credit + eitc
* recode ctccrd actccrd eitcred (9999 99999 999999 = 0)
* gen credits = ctccrd + actccrd + eitcred

* family market values of non-cash transfers: food stamps + school lunch + housing subsidies
* gen transfers =stampval +schllunch+ spmcaphous



sort state_fips year serial
* order  year dem_married serial relate sex nchild
*
* order  year dem_married serial relate sex age nchild nchildu18 dem_nchild

gen byte dem1 = age<65
gen byte dem2 = age>=0
gen byte dem3 = inrange(age,16,64)
gen byte dem4 = inrange(age,0,64) & inrange(dem_educ,1,2)
gen byte dem5 = inrange(age,16,24) & dem_educ == 1
gen byte dem6 =  sex==2 & nchild>0 & !inrange(marst,1,2)  & inrange(age,16,55)
gen byte dem7 = (dem_race==200 | dem_hisp==1) & age<65
gen byte dem8 = inrange(age,0,15)
gen byte dem9 = inrange(age,16,24) & dem_educ == 1
gen byte dem10 = inrange(age,18,29) & dem_educ == 1

cap drop itn_cutoff
gen     itn_cutoff = ""
replace itn_cutoff = "ITN1" if 0     <=contpov & contpov<.5
replace itn_cutoff = "ITN2" if .5    <=contpov & contpov<1
replace itn_cutoff = "ITN3" if 1     <=contpov & contpov<1.25
replace itn_cutoff = "ITN4" if 1.25  <=contpov & contpov<1.5
replace itn_cutoff = "ITN5" if 1.5   <=contpov & contpov<2
replace itn_cutoff = "ITN6" if 2     <=contpov & contpov<3
replace itn_cutoff = "ITN7" if 3     <=contpov & contpov!=.
